package com.bn.feed;

import java.io.IOException;

import javax.servlet.ServletException;

import atg.beans.DynamicPropertyDescriptor;
import atg.repository.MutableRepository;
import atg.repository.MutableRepositoryItem;
import atg.repository.Repository;
import atg.repository.RepositoryException;
import atg.repository.RepositoryItem;
import atg.repository.RepositoryItemDescriptor;
import atg.servlet.DynamoHttpServletRequest;
import atg.servlet.DynamoHttpServletResponse;
import atg.servlet.DynamoServlet;

public class BNFeedDroplet extends DynamoServlet{
	
	private Repository productCatalog;
	
	public Repository getProductCatalog() {
		return productCatalog;
	}

	public void setProductCatalog(Repository productCatalog) {
		this.productCatalog = productCatalog;
	}

	@Override
	public void doGet(DynamoHttpServletRequest request, DynamoHttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);

	}
	
	@Override
	public void doPost(DynamoHttpServletRequest request, DynamoHttpServletResponse response)
			throws ServletException, IOException {

		setProductDetails(request, response);

	}

	private void setProductDetails(DynamoHttpServletRequest request,DynamoHttpServletResponse response) {
		MutableRepository mutableRepository = (MutableRepository) productCatalog;
		MutableRepositoryItem mutableRepositoryItem = null;
		try {
				BNFeedConstants constants = new BNFeedConstants();
				if(mutableRepository != null){
					mutableRepositoryItem = mutableRepository.createItem(constants.PRODUCT_ITEM_DESC_NAME);
					mutableRepositoryItem.setPropertyValue(constants.PRODUCT_PROPERTY_DISPLAY_NAME, "Cherryprod004");
				}
				mutableRepository.addItem(mutableRepositoryItem);
				
		} catch (RepositoryException e) {
			if (isLoggingError()) {
                logError("Error while setting default shipping address", e);
            }
		}
		
	}
}
